package krao.data;

/**
 * Abstract class for storing data for one atom of a query.
 * 
 * @see ClassAtom
 * @see RoleAtom
 * 
 * @author Pepe
 * 
 */
public abstract class Atom implements Cloneable {
	private String name;

	public Atom(String name) {
		this.setName(name);
	}

	/**
	 * Returns value of the argument
	 * 
	 * @param arg
	 *            string to determine argument by
	 * @return null in case null or _ is supplied, string arg otherwise
	 */
	protected String getArg(String arg) {
		if (arg == null) {
			return null;
		} else {
			return arg.equals("_") ? null : arg;
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFirstArg() {
		return null;
	};

	public String getSecondArg() {
		return null;
	};

	public void setFirstArg(String arg) {
	}

	public void setSecondArg(String arg) {
	};

	/**
	 * String used in determining unbound variables. Only variable parameters
	 * are taken into account.
	 * 
	 * @return string in format
	 */
	public String getArgString() {
		return "";
	}

	/**
	 * Hash code produced by hashing string consisting of tokens 1 + name + 2 +
	 * arg1 + 3 + arg2.
	 */
	@Override
	public int hashCode() {
		return String.format("1%s2%s3%s", getName(), getFirstArg(), getSecondArg())
				.hashCode();
	}

	/**
	 * 
	 * @return true if this instance is ClassAtom, false otherwise.
	 */
	public boolean isClassAtom() {
		return false;
	}

	/**
	 * The atom is empty, if it has no non-null arguemnts.
	 */
	public boolean isEmpty() {
		return false;
	}

	@Override
	public Object clone() {
		return new Object();
	}

	public Atom unify(Atom atom) {
		return null;
	}

	public boolean getFirstArgVariable() {
		return false;
	}

	public boolean getSecondArgVariable() {
		return false;
	}

	public int getArgPosition(String argName) {
		return 0;
	}
}
